<template>
   <div :ref="refName" :style="{ height: height, width: width }" />
</template>

<script>
import resize from "@/mixins/chartResize";

export default {
  props:{
    // 样式
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    refName: {
      type: String,
      default: "centerLeft1Chart",
    },
  },
  data() {
    return {
      chart: null
    };
  },
  mixins: [resize],
  mounted() {
    this.$nextTick(()=>{
      this.draw();
    })
  },
  methods: {
    draw() {
      this.chart = this.$echarts.init(this.$refs[this.refName]);
      this.chart.setOption({
        color: [
          "#37a2da",
          "#32c5e9",
          "#9fe6b8",
          "#ffdb5c",
          "#ff9f7f",
          "#fb7293",
          "#e7bcf3",
          "#8378ea"
        ],
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        toolbox: {
          show: true
        },
        calculable: true,
        legend: {
          orient: "horizontal",
          icon: "circle",
          bottom: 0,
          x: "center",
          data: ["rose1", "rose2", "rose3", "rose4", "rose5", "rose6"],
          textStyle: {
            color: "#fff"
          }
        },
        series: [
          {
            name: "增值电信业务统计表",
            type: "pie",
            radius: [10, 40],
            roseType: "area",
            center: ["50%", "40%"],
            data: [
              { value: 10, name: "rose1" },
              { value: 5, name: "rose2" },
              { value: 15, name: "rose3" },
              { value: 25, name: "rose4" },
              { value: 20, name: "rose5" },
              { value: 35, name: "rose6" }
            ]
          }
        ]
      });
    }
  },
};
</script>
